package com.mysoftbase.base.config;

import com.mysoftbase.base.intercetpor.BaseIntercetpor;
import com.mysoftbase.base.intercetpor.TestIntercetpor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: JohnCoding
 * @Description:
 * @date: 2019/12/26 9:36
 */
@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    @Autowired
    BaseIntercetpor baseIntercetpor;

    @Autowired
    TestIntercetpor testIntercetpor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        System.out.println("跨域时配置,若使用nginx反向代理,则没有跨域问题");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("注册拦截器");
        //注册多个拦截器,最前面的最新执行
        registry.addInterceptor(testIntercetpor).addPathPatterns("/**");
        registry.addInterceptor(baseIntercetpor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html");
        System.out.println("如有多个拦截器，可以接着在这里注册");
    }


}
